<template>

    <div class="global">
        <div>
            <el-button @click="share" :disabled="selectlists.length == 0" type="primary">取消分享</el-button>
        </div>
        <div>
            <ShareTable @selectlist="selectlist" @reset="reset" :tableData="tableData"></ShareTable>
        </div>
        <Pagnition @changepage="changelist" :params="params" :total="total"></Pagnition>


    </div>
</template>

<script setup>
import { ElMessage, ElMessageBox } from 'element-plus'
import Pagnition from "@/component/Pagnition.vue";
import ShareTable from "@/component/ShareTable.vue"
import service from "@/utils/Request";
import { onMounted, ref } from "vue";
const tableData = ref([])
const selectdata = ref([])
const selectlists = ref([])
const params = ref({
    pageNo: 1,
    pageSize: 10
})
const total = ref(0)
const changelist = (e) => {
    console.log(e)
    params.value.pageNo = e.pageNo,
        params.value.pageSize = e.pageSize;
    gettablelist()
}
const gettablelist = async () => {
    const res = await service.post("/share/loadShareList", params.value);
    console.log(res)
    tableData.value = res.data.records
    total.value = res.data.total
}

const selectlist = (e) => {
    console.log(e)
    let data = [];
    selectlists.value = e
    selectlists.value.forEach(el => {
        data.push(el.shareId)
    });
    selectdata.value = data

}
const share = () => {
    resetshare(selectdata.value);
}
const reset = (e) => {
    console.log(e)
    let data = [];
    data.push(e.shareId)
    resetshare(data)
}
const resetshare = async (data) => {
    ElMessageBox.confirm(
        `是否确认取消分享?`,
        'Warning',
        {
            confirmButtonText: 'OK',
            cancelButtonText: 'Cancel',
            type: 'warning',
        }
    )
        .then(async () => {
            const res = await service.post("/share/cancelShare", {
                shareIds: data.join(",")
            })
            console.log(res);
            if (res.code == 1) {
                ElMessage({
                    type: 'success',
                    message: "成功"
                })
                gettablelist()
            } else {
                ElMessage({
                    type: 'warning',
                    message: "失败"
                })

            }

        })

}
onMounted(() => {
    gettablelist()
})
</script>
